# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def pathSum(self, root: TreeNode, target: int) -> List[List[int]]:
        def recur(node, t):
            res = []
            if node.left:
                l = recur(node.left, t-node.val)
                if l:
                    res.extend([[node.val]+i for i in l])
            if node.right:
                r = recur(node.right, t-node.val)
                if r:
                    res.extend([[node.val]+i for i in r])
            if not node.left and not node.right and node.val == t:
                res.append([node.val])
            return res
        
        if root:
            return recur(root, target)
        else:
            return []